package com.cloudwise.controller;

import cn.hutool.http.HttpRequest;
import com.cloudwise.entity.Emp;
import com.cloudwise.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/11/18 15:20
 * @description：我的第一个controller
 * @modified By：
 * @version: 1.0
 */
@Controller
public class EmpMvcController {
    @Autowired
    private EmpService empService;
    @RequestMapping("/showEmp")
    public String showEmp(HttpSession session){
        List<Emp> empList = empService.findAllEmp();
        session.setAttribute("empList",empList);
        return "showEmpMvc";
    }
    @RequestMapping("/showEmpJson")
    @ResponseBody
    public List<Emp> showEmpJson(){
        List<Emp> empList = empService.findAllEmp();
        return empList;
    }

   /* @RequestMapping("deleteEmpById")
    public String deleteEmpById(HttpServletRequest request){
        String empno = request.getParameter("empno");
        int empnoInt = Integer.parseInt(empno);
        System.out.println("empnoInt："+empnoInt);
        System.out.println("删除方法开始执行！");
        return "redirect:showEmp";
    }*/
   @RequestMapping("deleteEmpById")
   public String deleteEmpById(Integer  empno){
      /* System.out.println("empno："+empno);
       System.out.println("删除方法开始执行！");*/
      //调用service层的删除方法删除emp
       empService.deleteEmpById(empno);
       return "redirect:showEmp";
   }
}
